package com.atguigu.springcloud.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

/**
 * @author liuzemin
 * @date 2020/11/24 14:18
 * @description
 */
@Service
public class PaymentService {
    public String paymentInfo_Ok(Integer id){
        return "线程池"+Thread.currentThread().getName()+"paymentInfo_Ok, id:  "+id+"/t"+"hahahaah哈哈~~~";
    }

    @HystrixCommand(fallbackMethod = "paymentInfo_TimeOutHandler",commandProperties = {
            @HystrixProperty(name="execution.isolation.thread.timeoutInMilliseconds",value="3000")
    })
    public String paymentInfo_TimeOut(Integer id){
        int timeNumber = 5000;
//        int age = 10/0;
        try {
            TimeUnit.MILLISECONDS.sleep(timeNumber);
        }catch (InterruptedException e){
            e.printStackTrace();
        }
        return "线程池"+Thread.currentThread().getName()+"paymentInfo_TimeOut, id:  "+id+"/t"+"haha呵呵haah~~~"+"耗时(s):"+timeNumber;
    }
    public String paymentInfo_TimeOutHandler(Integer id){
        return "线程池"+Thread.currentThread().getName()+"系统繁忙或者运行报错，稍后再试, id:  "+id+"/t"+"haha哇啊哇哇哇哇哇haah~~~";
    }
}
